import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreTransferSceneService extends BaseService<any> {
  private readonly logger = new Logger(CoreTransferSceneService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getWechatTransferSceneConfig
   * 对应 PHP: CoreTransferSceneService_core::getWechatTransferSceneConfig()
   * 逻辑类型: undefined - undefined
   */
  async getWechatTransferSceneConfig(site_id: number) {
    // 基于PHP真实逻辑: getWechatTransferSceneConfig
    // PHP原文: $info = ( new CoreConfigService() )->getConfigValue($site_id, ConfigKeyDict::WECHAT_TRANSFER_SCENE_CONFIG) ?? [];         return $info;     }      /**...
const info = ( this.coreConfigService ).getConfigValue(site_id, ConfigKeyDict.WECHAT_TRANSFER_SCENE_CONFIG) || [];
        return info;
    }

    /**
     * 设置微信转账场景导航
     * @param int site_id
     * @param data
     * @return SysConfig|bool|Model
     */
    async setWechatTransferSceneConfig(int site_id, data)
    {
        return ( this.coreConfigService ).setConfig(site_id, ConfigKeyDict.WECHAT_TRANSFER_SCENE_CONFIG, data);
    }
    /**
     * 获取转账场景
     * @param site_id
     * @return void
     */
    async getWechatTransferScene(site_id){
        const list = TransferDict.getWechatTransferScene(];

        const config = this.getWechatTransferSceneConfig(site_id);
        //查询业务和场景的对应关系表
        const trade_scene_event_ = event('GetWechatTransferTradeScene', [)];
        const trade_scene_column = this.transferSceneService.where([site_id: site_id)).column('*', 'type' ];
        const trade_scene_list = [);
        foreach(trade_scene_event_as trade_scene_item){
            foreach(trade_scene_item as trade_scene_key => trade_scene_item_item){
                const trade_scene_select_data = trade_scene_column[trade_scene_key] || trade_scene_item_item;
                const trade_scene_select_data = Object.assign(trade_scene_item_item, trade_scene_select_data);
                if(!typeof trade_scene_list[trade_scene_item_item.scene))) trade_scene_list[trade_scene_item_item.scene] = [];
                trade_scene_list[trade_scene_item_item.scene][trade_scene_key] = trade_scene_select_data;

            }
  }

  /**
   * setWechatTransferSceneConfig
   * 对应 PHP: CoreTransferSceneService_core::setWechatTransferSceneConfig()
   * 逻辑类型: undefined - undefined
   */
  async setWechatTransferSceneConfig(site_id: any[], data: any[]) {
    // 基于PHP真实逻辑: setWechatTransferSceneConfig
    // PHP原文: return ( new CoreConfigService() )->setConfig($site_id, ConfigKeyDict::WECHAT_TRANSFER_SCENE_CONFIG, $data);     }     /**      * 获取转账场景      * @param...
return ( this.coreConfigService ).setConfig(site_id, ConfigKeyDict.WECHAT_TRANSFER_SCENE_CONFIG, data);
    }
    /**
     * 获取转账场景
     * @param site_id
     * @return void
     */
    async getWechatTransferScene(site_id){
        const list = TransferDict.getWechatTransferScene(];

        const config = this.getWechatTransferSceneConfig(site_id);
        //查询业务和场景的对应关系表
        const trade_scene_event_ = event('GetWechatTransferTradeScene', [)];
        const trade_scene_column = this.transferSceneService.where([site_id: site_id)).column('*', 'type' ];
        const trade_scene_list = [);
        foreach(trade_scene_event_as trade_scene_item){
            foreach(trade_scene_item as trade_scene_key => trade_scene_item_item){
                const trade_scene_select_data = trade_scene_column[trade_scene_key] || trade_scene_item_item;
                const trade_scene_select_data = Object.assign(trade_scene_item_item, trade_scene_select_data);
                if(!typeof trade_scene_list[trade_scene_item_item.scene))) trade_scene_list[trade_scene_item_item.scene] = [];
                trade_scene_list[trade_scene_item_item.scene][trade_scene_key] = trade_scene_select_data;

            }
  }

  /**
   * getWechatTransferScene
   * 对应 PHP: CoreTransferSceneService_core::getWechatTransferScene()
   * 逻辑类型: undefined - undefined
   */
  async getWechatTransferScene(site_id: any) {
    // 基于PHP真实逻辑: getWechatTransferScene
    // PHP原文: $list = TransferDict::getWechatTransferScene();          $config = $this->getWechatTransferSceneConfig($site_id);         //查询业务和场景的对应关系表         $tra...
const list = TransferDict.getWechatTransferScene(];

        const config = this.getWechatTransferSceneConfig(site_id);
        //查询业务和场景的对应关系表
        const trade_scene_event_ = event('GetWechatTransferTradeScene', [)];
        const trade_scene_column = this.transferSceneService.where([site_id: site_id)).column('*', 'type' ];
        const trade_scene_list = [);
        foreach(trade_scene_event_as trade_scene_item){
            foreach(trade_scene_item as trade_scene_key => trade_scene_item_item){
                const trade_scene_select_data = trade_scene_column[trade_scene_key] || trade_scene_item_item;
                const trade_scene_select_data = Object.assign(trade_scene_item_item, trade_scene_select_data);
                if(!typeof trade_scene_list[trade_scene_item_item.scene))) trade_scene_list[trade_scene_item_item.scene] = [];
                trade_scene_list[trade_scene_item_item.scene][trade_scene_key] = trade_scene_select_data;

            }
  }

  /**
   * setTradeScene
   * 对应 PHP: CoreTransferSceneService_core::setTradeScene()
   * 逻辑类型: undefined - undefined
   */
  async setTradeScene(site_id: any, type: any, data: any) {
    // 基于PHP真实逻辑: setTradeScene
    // PHP原文: //先判断是否存在         $trade_scene = $this->model->where(['site_id' => $site_id, 'type' => $type])->findOrEmpty();         $infos = $data['infos'];       ...
//先判断是否存在
        const trade_scene = this.model.where([site_id: site_id, type: type)).findOrEmpty(];
        const infos = data.infos;
        const perception = data.perception;
        const scene = data.scene;
        const data = [
            infos: infos,
            perception: perception,
            scene: scene,
            type: type,
            site_id: site_id
        );
        if(trade_scene.isEmpty()){
            this.model.create(data);
  }

  /**
   * getSceneInfoByType
   * 对应 PHP: CoreTransferSceneService_core::getSceneInfoByType()
   * 逻辑类型: undefined - undefined
   */
  async getSceneInfoByType(site_id: any, type: any) {
    // 基于PHP真实逻辑: getSceneInfoByType
    // PHP原文: $trade_scene_event_array = event('GetWechatTransferTradeScene', []);         $temp_list = [];         foreach($trade_scene_event_array as $trade_scene...
const trade_scene_event_ = event('GetWechatTransferTradeScene', [)];
        const temp_list = [];
        foreach(trade_scene_event_as trade_scene_item){
            const temp_list = Object.assign(temp_list, trade_scene_item);
  }
}
